
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>线程池的工作原理 · JAVA学习积累</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tianwyam">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="java_ftp.html" />
    
    
    <link rel="prev" href="java.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://blog.csdn.net/mybook201314" target="_blank" class="custom-link">博客Blog</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">【前言】</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍ABOUT
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第一章】Java基础</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="java.html">
            
                <a href="java.html">
            
                    
                    计算机基础-操作系统-进程-计算机网络
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.2" data-path="java_thread_pool.html">
            
                <a href="java_thread_pool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="java_ftp.html">
            
                <a href="java_ftp.html">
            
                    
                    FTP文件服务器上传下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="collection.html">
            
                <a href="collection.html">
            
                    
                    集合
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="collection/java_collection_map.html">
            
                <a href="collection/java_collection_map.html">
            
                    
                    Map&HashMap&HashTable&ConcurrentHashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="java_queue.html">
            
                <a href="java_queue.html">
            
                    
                    队列-queue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="java_tree.html">
            
                <a href="java_tree.html">
            
                    
                    二叉树遍历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="java_io_nio.html">
            
                <a href="java_io_nio.html">
            
                    
                    java输入输出流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="java_exception.html">
            
                <a href="java_exception.html">
            
                    
                    异常exception
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="java_serialize.html">
            
                <a href="java_serialize.html">
            
                    
                    Java序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="Java_annotation.html">
            
                <a href="Java_annotation.html">
            
                    
                    注解
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="multi.html">
            
                <a href="multi.html">
            
                    
                    多线程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="multithread/java_multi_thread_volatile_synchronized.html">
            
                <a href="multithread/java_multi_thread_volatile_synchronized.html">
            
                    
                    volatile&synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="multithread/java_multi_thread_object_wait_notify.html">
            
                <a href="multithread/java_multi_thread_object_wait_notify.html">
            
                    
                    object/wait/notify
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="multithread/java_multi_thread_thread.html">
            
                <a href="multithread/java_multi_thread_thread.html">
            
                    
                    thread
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="multithread/java_multi_thread_threadpool.html">
            
                <a href="multithread/java_multi_thread_threadpool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="multithread/java_multi_thread_lock.html">
            
                <a href="multithread/java_multi_thread_lock.html">
            
                    
                    lock&ReentrantLock&ReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="multithread/java_multi_thread_lock_condition.html">
            
                <a href="multithread/java_multi_thread_lock_condition.html">
            
                    
                    lock&condition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="multithread/java_multi_thread_tools.html">
            
                <a href="multithread/java_multi_thread_tools.html">
            
                    
                    Java并发工具- CountDownLatch&CyclicBarrier 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="multithread/java_multi_thread_tools2.html">
            
                <a href="multithread/java_multi_thread_tools2.html">
            
                    
                    Java同步工具类- CountDownLatch&CyclicBarrier&Semaphore  
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="java_jvm.html">
            
                <a href="java_jvm.html">
            
                    
                    java虚拟机-JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="java_java7new.html">
            
                <a href="java_java7new.html">
            
                    
                    java7新知识- Switch&TWR&Objects 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="java_stream.html">
            
                <a href="java_stream.html">
            
                    
                    Java8对集合流操作stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="java_stream_groupby.html">
            
                <a href="java_stream_groupby.html">
            
                    
                    java8新语法-Stream-分组groupingBy操作 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="java_optional.html">
            
                <a href="java_optional.html">
            
                    
                    java8新语法-Optional 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="java_8new_date_api.html">
            
                <a href="java_8new_date_api.html">
            
                    
                    java8-新的日期时间API 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../xml/xml_translation.html">
            
                <a href="../xml/xml_translation.html">
            
                    
                    XML中特殊符号的转译 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../datastructure/binary_complement.html">
            
                <a href="../datastructure/binary_complement.html">
            
                    
                    原码、反码、补码 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="basic/javabean2map.html">
            
                <a href="basic/javabean2map.html">
            
                    
                    Java bean转Map 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第二章】算法积累题</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../algorithm/merge_sorted_array.html">
            
                <a href="../algorithm/merge_sorted_array.html">
            
                    
                    算法题 - 合并排序数组 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="../algorithm/lowest_score.html">
            
                <a href="../algorithm/lowest_score.html">
            
                    
                    算法题 - 最低分数线问题 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="../algorithm/array_sub_list.html">
            
                <a href="../algorithm/array_sub_list.html">
            
                    
                    算法题 - 求数组的子集合 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第三章】框架</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../Spring/springboot.html">
            
                <a href="../Spring/springboot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="../Spring/spring_security.html">
            
                <a href="../Spring/spring_security.html">
            
                    
                    SpringSecurity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../linux/linux_commands_springboot_startup.html">
            
                <a href="../linux/linux_commands_springboot_startup.html">
            
                    
                    SpringBoot项目启动脚本
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="10.1" data-path="../Spring/spring/spring_interview_questions_68.html">
            
                <a href="../Spring/spring/spring_interview_questions_68.html">
            
                    
                    Spring面试题68
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="11.1" data-path="../Spring/springboot_auto_config.html">
            
                <a href="../Spring/springboot_auto_config.html">
            
                    
                    SpringBoot自动装载机制 - 源码分析
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="12.1" data-path="../Spring/spring_feign.html">
            
                <a href="../Spring/spring_feign.html">
            
                    
                    Feign在spring、springboot下使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="13.1" data-path="../Spring/spring_freemarker.html">
            
                <a href="../Spring/spring_freemarker.html">
            
                    
                    Spring boot集成freemarker，生成word文件
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="14.1" data-path="../Spring/spring_freemarker_generate.html">
            
                <a href="../Spring/spring_freemarker_generate.html">
            
                    
                    Freemarker自动生成Java bean代码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="15.1" data-path="../mybatis/mybatis_metadata.html">
            
                <a href="../mybatis/mybatis_metadata.html">
            
                    
                    mybatis中操作元数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.2" data-path="../mybatis/mybatis_batch_exec_sql.html">
            
                <a href="../mybatis/mybatis_batch_exec_sql.html">
            
                    
                    mybatis中insert/update/delete标签中执行多条SQL语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.3" data-path="../mybatis/mybatis_plus.html">
            
                <a href="../mybatis/mybatis_plus.html">
            
                    
                    springboot集成mybatis-plus框架
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="16.1" data-path="../distributed/sharding-jdbc.html">
            
                <a href="../distributed/sharding-jdbc.html">
            
                    
                    【分布式】sharding-jdbc实现分库分表
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第四章】数据库</li>
        
        
    
        <li class="chapter " data-level="17.1" data-path="../SQL/sql.html">
            
                <a href="../SQL/sql.html">
            
                    
                    SQL常用使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="18.1" data-path="../redis/redis_study_notes.html">
            
                <a href="../redis/redis_study_notes.html">
            
                    
                    redis学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="18.2" data-path="../redis/redis_list_second_kill.html">
            
                <a href="../redis/redis_list_second_kill.html">
            
                    
                    Redis中的队列list实现秒杀活动抢购
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="19.1" data-path="../SQL/sql_mysql_green_install.html">
            
                <a href="../SQL/sql_mysql_green_install.html">
            
                    
                    mysql绿色版安装服务教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.2" data-path="../SQL/sql_h2.html">
            
                <a href="../SQL/sql_h2.html">
            
                    
                    H2内嵌数据的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.3" data-path="../SQL/cache.html">
            
                <a href="../SQL/cache.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.4" data-path="../SQL/mysql/mysql_back_rollback.html">
            
                <a href="../SQL/mysql/mysql_back_rollback.html">
            
                    
                    MySQL单表备份还原
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第五章】Web</li>
        
        
    
        <li class="chapter " data-level="20.1" data-path="../web/web_js_jquery.html">
            
                <a href="../web/web_js_jquery.html">
            
                    
                    web简单积累
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第六章】Linux</li>
        
        
    
        <li class="chapter " data-level="21.1" data-path="../linux/linux_common_commands.html">
            
                <a href="../linux/linux_common_commands.html">
            
                    
                    linux常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第七章】Windows</li>
        
        
    
        <li class="chapter " data-level="22.1" data-path="../windows/windows_common_commands.html">
            
                <a href="../windows/windows_common_commands.html">
            
                    
                    windows常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第八章】错误集</li>
        
        
    
        <li class="chapter " data-level="23.1" data-path="../error/maven_not_found_local_jar.html">
            
                <a href="../error/maven_not_found_local_jar.html">
            
                    
                    maven引入依赖时识别不到本地仓库的jar
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="24.1" data-path="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                <a href="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                    
                    spring security 配置发生错误 Can't configure antMatchers after anyRequest
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="25.1" data-path="../error/AOP_stream_close_error.html">
            
                <a href="../error/AOP_stream_close_error.html">
            
                    
                    AOP内获取了对请求流操作后报流已经关闭错误的问题
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="26.1" data-path="../tools/github/github_ssh.html">
            
                <a href="../tools/github/github_ssh.html">
            
                    
                    Github ssh key 解决提交后push频繁输入用户名和密码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="27.1" data-path="../error/sharding-jdbc-error-datasources.html">
            
                <a href="../error/sharding-jdbc-error-datasources.html">
            
                    
                    sharding-jdbc-4.1.1版本启动数据源报错问题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >线程池的工作原理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><ul><li><span class="title-icon "></span><a href="#&#x7EBF;&#x7A0B;&#x6C60;"><b></b>&#x7EBF;&#x7A0B;&#x6C60;</a></li><ul><li><span class="title-icon "></span><a href="#1&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x4F7F;&#x7528;"><b></b>1.&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x4F7F;&#x7528;</a></li><li><span class="title-icon "></span><a href="#2&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x6838;&#x5FC3;&#x53C2;&#x6570;"><b></b>2.&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x6838;&#x5FC3;&#x53C2;&#x6570;</a></li><li><span class="title-icon "></span><a href="#3&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;"><b></b>3.&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;</a></li><li><span class="title-icon "></span><a href="#4&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x963B;&#x585E;&#x961F;&#x5217;"><b></b>4.&#x4EFB;&#x52A1;&#x961F;&#x5217;(&#x963B;&#x585E;&#x961F;&#x5217;)</a></li><li><span class="title-icon "></span><a href="#5&#x9971;&#x548C;&#x7B56;&#x7565;&#x62D2;&#x7EDD;&#x7B56;&#x7565;"><b></b>5.&#x9971;&#x548C;&#x7B56;&#x7565;(&#x62D2;&#x7EDD;&#x7B56;&#x7565;)</a></li><li><span class="title-icon "></span><a href="#6&#x4EFB;&#x52A1;&#x7684;&#x63D0;&#x4EA4;&#x6267;&#x884C;"><b></b>6.&#x4EFB;&#x52A1;&#x7684;&#x63D0;&#x4EA4;&#x6267;&#x884C;</a></li><li><span class="title-icon "></span><a href="#7&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5173;&#x95ED;"><b></b>7.&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5173;&#x95ED;</a></li><li><span class="title-icon "></span><a href="#8&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6C60;"><b></b>8.&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6C60;</a></li></ul></ul></ul></div><h2 id="&#x7EBF;&#x7A0B;&#x6C60;"><a name="&#x7EBF;&#x7A0B;&#x6C60;" class="anchor-navigation-ex-anchor" href="#&#x7EBF;&#x7A0B;&#x6C60;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x7EBF;&#x7A0B;&#x6C60;</h2>
<p>&#x4F18;&#x70B9;&#xFF1A;</p>
<p>&#x200B;    &#x7B2C;&#x4E00;&#xFF1A;&#x964D;&#x4F4E;&#x8D44;&#x6E90;&#x6D88;&#x8017;&#xFF0C;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x548C;&#x9500;&#x6BC1;&#x5341;&#x5206;&#x6D6A;&#x8D39;&#x8D44;&#x6E90;&#xFF0C;&#x7EBF;&#x7A0B;&#x6C60;&#x9884;&#x5148;&#x521B;&#x5EFA;&#x597D;&#x7EBF;&#x7A0B;&#xFF0C;&#x5E76;&#x91CD;&#x590D;&#x5229;&#x7528;&#x7EBF;&#x7A0B;&#xFF0C;&#x964D;&#x4F4E;&#x8D44;&#x6E90;&#x6D88;&#x8017;&#x3002;</p>
<p>&#x200B;    &#x7B2C;&#x4E8C;&#xFF1A;&#x63D0;&#x9AD8;&#x54CD;&#x5E94;&#x901F;&#x5EA6;&#xFF0C;&#x4EFB;&#x52A1;&#x4E0D;&#x9700;&#x8981;&#x7B49;&#x5F85;&#x7EBF;&#x7A0B;&#x7684;&#x521B;&#x5EFA;&#x5C31;&#x80FD;&#x76F4;&#x63A5;&#x6267;&#x884C;&#x3002;</p>
<p>&#x200B;    &#x7B2C;&#x4E09;&#xFF1A;&#x63D0;&#x9AD8;&#x7EBF;&#x7A0B;&#x7684;&#x53EF;&#x7BA1;&#x7406;&#x6027;&#xFF0C;&#x7EBF;&#x7A0B;&#x662F;&#x7A00;&#x7F3A;&#x8D44;&#x6E90;&#xFF0C;&#x5982;&#x679C;&#x65E0;&#x9650;&#x5236;&#x521B;&#x5EFA;&#xFF0C;&#x4E0D;&#x4EC5;&#x4F1A;&#x6D88;&#x8017;&#x7CFB;&#x7EDF;&#x8D44;&#x6E90;&#xFF0C;&#x8FD8;&#x4F1A;&#x964D;&#x4F4E;&#x7CFB;&#x7EDF;&#x7684;&#x7A33;&#x5B9A;&#x6027;&#xFF0C;&#x4F7F;&#x7528;&#x7EBF;&#x7A0B;&#x6C60;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x7EDF;&#x4E00;&#x7BA1;&#x7406;&#x3001;&#x5206;&#x914D;&#x3001;&#x8C03;&#x4F18;&#x3001;&#x76D1;&#x63A7;&#x7B49;&#x3002;</p>
<h3 id="1&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x4F7F;&#x7528;"><a name="1&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#1&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>1.&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x4F7F;&#x7528;</h3>
<p>&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x521B;&#x5EFA;&#xFF1A;<strong><em>ThreadPoolExecutor</em></strong></p>
<pre><code class="lang-java">java.util.concurrent.ThreadPoolExecutor
</code></pre>
<p>&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-java">ThreadPoolExecutor(<span class="hljs-keyword">int</span> corePoolSize,
                   <span class="hljs-keyword">int</span> maximumPoolSize,
                   <span class="hljs-keyword">long</span> keepAliveTime,
                   TimeUnit unit,
                   BlockingQueue&lt;Runnable&gt; workQueue,
                   ThreadFactory threadFactory,
                   RejectedExecutionHandler handler);
</code></pre>
<h3 id="2&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x6838;&#x5FC3;&#x53C2;&#x6570;"><a name="2&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x6838;&#x5FC3;&#x53C2;&#x6570;" class="anchor-navigation-ex-anchor" href="#2&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x6838;&#x5FC3;&#x53C2;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>2.&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x6838;&#x5FC3;&#x53C2;&#x6570;</h3>
<ul>
<li>corePoolSize&#xFF1A;&#x6838;&#x5FC3;&#x7EBF;&#x7A0B;&#x6570;</li>
<li>maximumPoolSize&#xFF1A;&#x6700;&#x5927;&#x7EBF;&#x7A0B;&#x6570;</li>
<li>keepAliveTime&#xFF1A;&#x7EBF;&#x7A0B;&#x6D3B;&#x52A8;&#x4FDD;&#x6301;&#x65F6;&#x95F4;</li>
<li>TimeUnit&#xFF1A;&#x7EBF;&#x7A0B;&#x6D3B;&#x52A8;&#x4FDD;&#x6301;&#x65F6;&#x95F4;&#x7684;&#x5355;&#x4F4D;&#xFF0C;&#x53EF;&#x9009;&#xFF1A;DAYS&#x3001;HOURS&#x3001;MINUTES&#x3001;SECONDS&#x3001;MILLISECONDS&#x7B49;</li>
<li>workQueue&#xFF1A;&#x4EFB;&#x52A1;&#x961F;&#x5217;&#xFF0C;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;&#x7B49;&#x5F85;&#x6267;&#x884C;&#x7684;&#x4EFB;&#x52A1;&#x7684;&#x963B;&#x585E;&#x961F;&#x5217;</li>
<li>threadFactory&#xFF1A;&#x7EBF;&#x7A0B;&#x5DE5;&#x5382;&#xFF0C;&#x7528;&#x4E8E;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x7684;&#x5DE5;&#x5382;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7EBF;&#x7A0B;&#x5DE5;&#x5382;&#x7ED9;&#x6BCF;&#x4E2A;&#x7EBF;&#x7A0B;&#x8BBE;&#x7F6E;&#x5177;&#x6709;&#x542B;&#x4E49;&#x7684;&#x7EBF;&#x7A0B;&#x540D;</li>
<li>RejectedExecutionHandler&#xFF1A;&#x9971;&#x548C;&#x7B56;&#x7565;(&#x62D2;&#x7EDD;&#x7B56;&#x7565;)</li>
</ul>
<h3 id="3&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;"><a name="3&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;" class="anchor-navigation-ex-anchor" href="#3&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>3.&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;</h3>
<p>&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x4E3B;&#x8981;&#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;</p>
<p><img src="https://img-blog.csdnimg.cn/20191019174315577.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L215Ym9vazIwMTMxNA==,size_16,color_FFFFFF,t_70" alt="Java&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;"></p>
<ol>
<li>&#x63D0;&#x4EA4;&#x4E00;&#x4E2A;&#x4EFB;&#x52A1;&#x5230;&#x7EBF;&#x7A0B;&#x6C60;&#x65F6;</li>
</ol>
<ol>
<li><p>&#x82E5;&#xFF1A;&#x7EBF;&#x7A0B;&#x6C60;&#x91CC;&#x5B58;&#x6D3B;&#x7684;&#x7EBF;&#x7A0B;&#x6570; &lt; &#x6838;&#x5FC3;&#x7EBF;&#x7A0B;&#x6570;corePoolSize&#xFF0C;&#x5219;&#x7EBF;&#x7A0B;&#x6C60;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x6765;&#x6267;&#x884C;&#x4EFB;&#x52A1;&#x3002;</p>
<p>&#x65B0;&#x521B;&#x5EFA;&#x7684;&#x8FD9;&#x4E2A;&#x7EBF;&#x7A0B;&#x4F1A;&#x4E00;&#x76F4;&#x5B58;&#x6D3B;&#x7740;&#xFF0C;&#x5C31;&#x7B97;&#x7A7A;&#x95F2;&#x65F6;&#x95F4;&#x8D85;&#x8FC7;&#x4E86;keepAliveTime&#xFF0C;&#x7EBF;&#x7A0B;&#x4E5F;&#x4E0D;&#x4F1A;&#x88AB;&#x9500;&#x6BC1;&#xFF0C;&#x800C;&#x662F;&#x4E00;&#x76F4;&#x963B;&#x585E;&#x5728;&#x90A3;&#x91CC;&#x4E00;&#x76F4;&#x7B49;&#x5F85;&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x7684;&#x4EFB;&#x52A1;&#x6765;&#x6267;&#x884C;&#x3002;</p>
<p>&#x5982;&#x679C;&#x8C03;&#x7528;&#x4E86;&#x7EBF;&#x7A0B;&#x6C60;&#x7684;prestartAllCoreThreads&#x65B9;&#x6CD5;&#xFF0C;&#x5219;&#x7EBF;&#x7A0B;&#x6C60;&#x4F1A;&#x63D0;&#x524D;&#x521B;&#x5EFA;&#x5E76;&#x542F;&#x52A8;&#x6240;&#x6709;&#x57FA;&#x672C;&#x7EBF;&#x7A0B;&#x3002;</p>
</li>
</ol>
<ol>
<li>&#x82E5;&#xFF1A;&#x7EBF;&#x7A0B;&#x6C60;&#x91CC;&#x5B58;&#x6D3B;&#x7684;&#x7EBF;&#x7A0B;&#x6570; = &#x6838;&#x5FC3;&#x7EBF;&#x7A0B;&#x6570;corePoolSize&#xFF0C;&#x5219;&#x65B0;&#x63D0;&#x4EA4;&#x7684;&#x4EFB;&#x52A1;&#x4F1A;&#x88AB;&#x653E;&#x8FDB;&#x4EFB;&#x52A1;&#x961F;&#x5217;workQueue&#x91CC;&#x6392;&#x961F;&#xFF0C;&#x7B49;&#x5F85;&#x6267;&#x884C;&#x3002;</li>
</ol>
<ol>
<li><p>&#x82E5;&#xFF1A;&#x7EBF;&#x7A0B;&#x6C60;&#x91CC;&#x5B58;&#x6D3B;&#x7684;&#x7EBF;&#x7A0B;&#x6570; = &#x6838;&#x5FC3;&#x7EBF;&#x7A0B;&#x6570;corePoolSize&#xFF0C;&#x5E76;&#x4E14;&#x4EFB;&#x52A1;&#x961F;&#x5217;workQueue&#x4E5F;&#x6EE1;&#x4E86;&#xFF0C;&#x5219;&#x7EBF;&#x7A0B;&#x6C60;&#x5C31;&#x4F1A;&#x7EE7;&#x7EED;&#x521B;&#x5EFA;&#x65B0;&#x7684;&#x7EBF;&#x7A0B;&#x6765;&#x5904;&#x7406;&#x65B0;&#x7684;&#x4EFB;&#x52A1;&#xFF0C;&#x76F4;&#x5230;&#x7EBF;&#x7A0B;&#x6570;&#x8FBE;&#x5230;maximumPoolSize&#xFF0C;&#x5C31;&#x4E0D;&#x4F1A;&#x518D;&#x521B;&#x5EFA;&#x4E86;&#x3002;</p>
<p>&#x8FD9;&#x4E9B;&#x65B0;&#x521B;&#x5EFA;&#x7684;&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x5B8C;&#x4E86;&#x5F53;&#x524D;&#x4EFB;&#x52A1;&#x8FC7;&#x540E;&#xFF0C;&#x5728;&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x91CC;&#x9762;&#x8FD8;&#x6709;&#x4EFB;&#x52A1;&#x7684;&#x65F6;&#x5019;&#x4E5F;&#x4E0D;&#x4F1A;&#x9500;&#x6BC1;&#xFF0C;&#x800C;&#x662F;&#x53BB;&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x62FF;&#x4EFB;&#x52A1;&#x51FA;&#x6765;&#x6267;&#x884C;&#x3002;&#x5728;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x6570;&#x5927;&#x4E8E;corePoolSize&#x8FC7;&#x540E;&#xFF0C;&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x5B8C;&#x5F53;&#x524D;&#x4EFB;&#x52A1;&#xFF0C;&#x4F1A;&#x6709;&#x4E00;&#x4E2A;&#x5224;&#x65AD;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x662F;&#x5426;&#x9700;&#x8981;&#x9500;&#x6BC1;&#x7684;&#x903B;&#x8F91;&#xFF1A;&#x5982;&#x679C;&#x80FD;&#x4ECE;&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x4E2D;&#x62FF;&#x5230;&#x4EFB;&#x52A1;&#xFF0C;&#x90A3;&#x4E48;&#x7EE7;&#x7EED;&#x6267;&#x884C;&#xFF0C;&#x5982;&#x679C;&#x62FF;&#x4EFB;&#x52A1;&#x65F6;&#x963B;&#x585E;&#xFF08;&#x8BF4;&#x660E;&#x961F;&#x5217;&#x4E2D;&#x6CA1;&#x6709;&#x4EFB;&#x52A1;&#xFF09;&#xFF0C;&#x90A3;&#x8D85;&#x8FC7;keepAliveTime&#x65F6;&#x95F4;&#x5C31;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;null&#xFF0C;&#x5E76;&#x4E14;&#x9500;&#x6BC1;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#xFF0C;&#x76F4;&#x5230;&#x7EBF;&#x7A0B;&#x6C60;&#x91CC;&#x9762;&#x7684;&#x7EBF;&#x7A0B;&#x6570;&#x7B49;&#x4E8E;corePoolSize&#x4E4B;&#x540E;&#x624D;&#x4E0D;&#x4F1A;&#x8FDB;&#x884C;&#x7EBF;&#x7A0B;&#x9500;&#x6BC1;&#x3002;</p>
</li>
</ol>
<ol>
<li>&#x82E5;&#xFF1A;&#x7EBF;&#x7A0B;&#x6C60;&#x91CC;&#x5B58;&#x6D3B;&#x7684;&#x7EBF;&#x7A0B;&#x6570; = maximumPoolSize&#xFF0C;&#x5E76;&#x4E14;&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x4E5F;&#x6EE1;&#x4E86;&#xFF0C;&#x5219;&#x65B0;&#x4EFB;&#x52A1;&#x5C06;&#x4F1A;&#x91C7;&#x7528;&#x9971;&#x548C;&#x7B56;&#x7565;(&#x62D2;&#x7EDD;&#x7B56;&#x7565;)&#x7684;&#x5904;&#x7406;&#x5668;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x3002;</li>
</ol>
<h3 id="4&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x963B;&#x585E;&#x961F;&#x5217;"><a name="4&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x963B;&#x585E;&#x961F;&#x5217;" class="anchor-navigation-ex-anchor" href="#4&#x4EFB;&#x52A1;&#x961F;&#x5217;&#x963B;&#x585E;&#x961F;&#x5217;"><i class="fa fa-link" aria-hidden="true"></i></a>4.&#x4EFB;&#x52A1;&#x961F;&#x5217;(&#x963B;&#x585E;&#x961F;&#x5217;)</h3>
<ul>
<li>ArrayBlockingQueue&#xFF1A;&#x662F;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E;&#x6570;&#x7EC4;&#x7ED3;&#x6784;&#x7684;&#x6709;&#x754C;&#x963B;&#x585E;&#x961F;&#x5217;&#xFF0C;&#x6B64;&#x961F;&#x5217;&#x6309; FIFO&#xFF08;&#x5148;&#x8FDB;&#x5148;&#x51FA;&#xFF09;&#x539F;&#x5219;&#x5BF9;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</li>
</ul>
<ul>
<li>LinkedBlockingQueue&#xFF1A;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E;&#x94FE;&#x8868;&#x7ED3;&#x6784;&#x7684;&#x963B;&#x585E;&#x961F;&#x5217;&#xFF0C;&#x6B64;&#x961F;&#x5217;&#x6309;FIFO &#xFF08;&#x5148;&#x8FDB;&#x5148;&#x51FA;&#xFF09; &#x6392;&#x5E8F;&#x5143;&#x7D20;&#xFF0C;&#x541E;&#x5410;&#x91CF;&#x901A;&#x5E38;&#x8981;&#x9AD8;&#x4E8E;ArrayBlockingQueue&#x3002;&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;Executors.newFixedThreadPool()&#x4F7F;&#x7528;&#x4E86;&#x8FD9;&#x4E2A;&#x961F;&#x5217;&#x3002;</li>
</ul>
<ul>
<li>SynchronousQueue&#xFF1A;&#x4E00;&#x4E2A;&#x4E0D;&#x5B58;&#x50A8;&#x5143;&#x7D20;&#x7684;&#x963B;&#x585E;&#x961F;&#x5217;&#x3002;&#x6BCF;&#x4E2A;&#x63D2;&#x5165;&#x64CD;&#x4F5C;&#x5FC5;&#x987B;&#x7B49;&#x5230;&#x53E6;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;&#x79FB;&#x9664;&#x64CD;&#x4F5C;&#xFF0C;&#x5426;&#x5219;&#x63D2;&#x5165;&#x64CD;&#x4F5C;&#x4E00;&#x76F4;&#x5904;&#x4E8E;&#x963B;&#x585E;&#x72B6;&#x6001;&#xFF0C;&#x541E;&#x5410;&#x91CF;&#x901A;&#x5E38;&#x8981;&#x9AD8;&#x4E8E;LinkedBlockingQueue&#xFF0C;&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;Executors.newCachedThreadPool&#x4F7F;&#x7528;&#x4E86;&#x8FD9;&#x4E2A;&#x961F;&#x5217;&#x3002;</li>
</ul>
<ul>
<li>PriorityBlockingQueue&#xFF1A;&#x4E00;&#x4E2A;&#x5177;&#x6709;&#x4F18;&#x5148;&#x7EA7;&#x7684;&#x65E0;&#x9650;&#x963B;&#x585E;&#x961F;&#x5217;</li>
</ul>
<h3 id="5&#x9971;&#x548C;&#x7B56;&#x7565;&#x62D2;&#x7EDD;&#x7B56;&#x7565;"><a name="5&#x9971;&#x548C;&#x7B56;&#x7565;&#x62D2;&#x7EDD;&#x7B56;&#x7565;" class="anchor-navigation-ex-anchor" href="#5&#x9971;&#x548C;&#x7B56;&#x7565;&#x62D2;&#x7EDD;&#x7B56;&#x7565;"><i class="fa fa-link" aria-hidden="true"></i></a>5.&#x9971;&#x548C;&#x7B56;&#x7565;(&#x62D2;&#x7EDD;&#x7B56;&#x7565;)</h3>
<p>RejectedExecutionHandler&#xFF08;&#x9971;&#x548C;&#x7B56;&#x7565;&#xFF09;&#xFF1A;&#x5F53;&#x961F;&#x5217;&#x548C;&#x7EBF;&#x7A0B;&#x6C60;&#x90FD;&#x6EE1;&#x4E86;&#xFF0C;&#x8BF4;&#x660E;&#x7EBF;&#x7A0B;&#x6C60;&#x5904;&#x4E8E;&#x9971;&#x548C;&#x72B6;&#x6001;&#xFF0C;&#x90A3;&#x4E48;&#x5FC5;&#x987B;&#x91C7;&#x53D6;&#x4E00;&#x79CD;&#x7B56;&#x7565;&#x5904;&#x7406;&#x63D0;&#x4EA4;&#x7684;&#x65B0;&#x4EFB;&#x52A1;&#x3002;&#x8FD9;&#x4E2A;&#x7B56;&#x7565;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x662F;AbortPolicy&#xFF0C;&#x8868;&#x793A;&#x65E0;&#x6CD5;&#x5904;&#x7406;&#x65B0;&#x4EFB;&#x52A1;&#x65F6;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x3002;&#x4EE5;&#x4E0B;&#x662F;JDK1.5&#x63D0;&#x4F9B;&#x7684;&#x56DB;&#x79CD;&#x7B56;&#x7565;&#x3002;</p>
<ul>
<li>AbortPolicy&#xFF1A;&#x76F4;&#x63A5;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x3002;</li>
<li>CallerRunsPolicy&#xFF1A;&#x4EA4;&#x7ED9;&#x8C03;&#x7528;&#x7EBF;&#x7A0B;&#x6C60;&#x6240;&#x5728;&#x7684;&#x7EBF;&#x7A0B;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x3002;</li>
<li>DiscardOldestPolicy&#xFF1A;&#x4E22;&#x5F03;&#x961F;&#x5217;&#x91CC;&#x6700;&#x8001;&#x7684;&#x4EFB;&#x52A1;&#xFF0C;&#x5C06;&#x5F53;&#x524D;&#x8FD9;&#x4E2A;&#x4EFB;&#x52A1;&#x7EE7;&#x7EED;&#x63D0;&#x4EA4;&#x7ED9;&#x7EBF;&#x7A0B;&#x6C60;&#x3002;</li>
<li>DiscardPolicy&#xFF1A;&#x4E0D;&#x5904;&#x7406;&#xFF0C;&#x76F4;&#x63A5;&#x4E22;&#x5F03;&#x6389;&#x3002;</li>
<li>&#x81EA;&#x5B9A;&#x4E49;&#x7B56;&#x7565;&#xFF0C;&#x5B9E;&#x73B0;RejectedExecutionHandler&#x63A5;&#x53E3;&#x81EA;&#x5B9A;&#x4E49;&#x7B56;&#x7565;&#x3002;&#x5982;&#x8BB0;&#x5F55;&#x65E5;&#x5FD7;&#x6216;&#x6301;&#x4E45;&#x5316;&#x4E0D;&#x80FD;&#x5904;&#x7406;&#x7684;&#x4EFB;&#x52A1;&#x3002;</li>
</ul>
<h3 id="6&#x4EFB;&#x52A1;&#x7684;&#x63D0;&#x4EA4;&#x6267;&#x884C;"><a name="6&#x4EFB;&#x52A1;&#x7684;&#x63D0;&#x4EA4;&#x6267;&#x884C;" class="anchor-navigation-ex-anchor" href="#6&#x4EFB;&#x52A1;&#x7684;&#x63D0;&#x4EA4;&#x6267;&#x884C;"><i class="fa fa-link" aria-hidden="true"></i></a>6.&#x4EFB;&#x52A1;&#x7684;&#x63D0;&#x4EA4;&#x6267;&#x884C;</h3>
<pre><code class="lang-java"><span class="hljs-comment">// &#x6267;&#x884C;&#x5B9E;&#x73B0;Runnable&#x63A5;&#x53E3;&#x7684;&#x4EFB;&#x52A1;</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">execute</span><span class="hljs-params">(Runnable command)</span> </span>;

<span class="hljs-comment">// &#x6267;&#x884C;&#x5B9E;&#x73B0;Callable&#x63A5;&#x53E3;&#x7684;&#x4EFB;&#x52A1;&#xFF0C;&#x53EF;&#x4EE5;&#x6709;&#x8FD4;&#x56DE;&#x503C;</span>
<span class="hljs-keyword">public</span> &lt;T&gt; <span class="hljs-function">Future&lt;T&gt; <span class="hljs-title">submit</span><span class="hljs-params">(Callable&lt;T&gt; task)</span>&#xFF1B;
</span></code></pre>
<h3 id="7&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5173;&#x95ED;"><a name="7&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5173;&#x95ED;" class="anchor-navigation-ex-anchor" href="#7&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5173;&#x95ED;"><i class="fa fa-link" aria-hidden="true"></i></a>7.&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x5173;&#x95ED;</h3>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8C03;&#x7528;&#x7EBF;&#x7A0B;&#x6C60;&#x7684;shutdown&#x6216;shutdownNow&#x65B9;&#x6CD5;&#x6765;&#x5173;&#x95ED;&#x7EBF;&#x7A0B;&#x6C60;</p>
<p>&#x539F;&#x7406;&#x662F;&#xFF1A;&#x904D;&#x5386;&#x7EBF;&#x7A0B;&#x6C60;&#x4E2D;&#x7684;&#x5DE5;&#x4F5C;&#x7EBF;&#x7A0B;&#xFF0C;&#x7136;&#x540E;&#x9010;&#x4E2A;&#x8C03;&#x7528;&#x7EBF;&#x7A0B;&#x7684;interrupt&#x65B9;&#x6CD5;&#x6765;&#x4E2D;&#x65AD;&#x7EBF;&#x7A0B;</p>
<p>&#x6240;&#x4EE5;&#x65E0;&#x6CD5;&#x54CD;&#x5E94;&#x4E2D;&#x65AD;&#x7684;&#x4EFB;&#x52A1;&#x53EF;&#x80FD;&#x6C38;&#x8FDC;&#x65E0;&#x6CD5;&#x7EC8;&#x6B62;</p>
<pre><code class="lang-java"><span class="hljs-comment">// shutdown &#x53EA;&#x662F;&#x5C06;&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x72B6;&#x6001;&#x8BBE;&#x7F6E;&#x6210;SHUTDOWN&#x72B6;&#x6001;&#xFF0C;&#x7136;&#x540E;&#x4E2D;&#x65AD;&#x6240;&#x6709;&#x6CA1;&#x6709;&#x6B63;&#x5728;&#x6267;&#x884C;&#x4EFB;&#x52A1;&#x7684;&#x7EBF;&#x7A0B;</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">shutdown</span><span class="hljs-params">()</span> </span>;

<span class="hljs-comment">// &#x9996;&#x5148;&#x5C06;&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x72B6;&#x6001;&#x8BBE;&#x7F6E;&#x6210;STOP&#xFF0C;&#x7136;&#x540E;&#x5C1D;&#x8BD5;&#x505C;&#x6B62;&#x6240;&#x6709;&#x7684;&#x6B63;&#x5728;&#x6267;&#x884C;&#x6216;&#x6682;&#x505C;&#x4EFB;&#x52A1;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x7B49;&#x5F85;&#x6267;&#x884C;&#x4EFB;&#x52A1;&#x7684;&#x5217;&#x8868;</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;Runnable&gt; <span class="hljs-title">shutdownNow</span><span class="hljs-params">()</span></span>;
</code></pre>
<p>&#x53EA;&#x8981;&#x8C03;&#x7528;&#x4E86;&#x8FD9;&#x4E24;&#x4E2A;&#x5173;&#x95ED;&#x65B9;&#x6CD5;&#x7684;&#x5176;&#x4E2D;&#x4E00;&#x4E2A;&#xFF0C;isShutdown&#x65B9;&#x6CD5;&#x5C31;&#x4F1A;&#x8FD4;&#x56DE;true&#x3002;</p>
<p>&#x5F53;&#x6240;&#x6709;&#x7684;&#x4EFB;&#x52A1;&#x90FD;&#x5DF2;&#x5173;&#x95ED;&#x540E;,&#x624D;&#x8868;&#x793A;&#x7EBF;&#x7A0B;&#x6C60;&#x5173;&#x95ED;&#x6210;&#x529F;&#xFF0C;&#x8FD9;&#x65F6;&#x8C03;&#x7528;isTerminaed&#x65B9;&#x6CD5;&#x4F1A;&#x8FD4;&#x56DE;true&#x3002;</p>
<p>&#x81F3;&#x4E8E;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x8C03;&#x7528;&#x54EA;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;&#x6765;&#x5173;&#x95ED;&#x7EBF;&#x7A0B;&#x6C60;&#xFF0C;&#x5E94;&#x8BE5;&#x7531;&#x63D0;&#x4EA4;&#x5230;&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x4EFB;&#x52A1;&#x7279;&#x6027;&#x51B3;&#x5B9A;&#xFF0C;&#x901A;&#x5E38;&#x8C03;&#x7528;shutdown&#x6765;&#x5173;&#x95ED;&#x7EBF;&#x7A0B;&#x6C60;&#xFF0C;&#x5982;&#x679C;&#x4EFB;&#x52A1;&#x4E0D;&#x4E00;&#x5B9A;&#x8981;&#x6267;&#x884C;&#x5B8C;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x8C03;&#x7528;shutdownNow</p>
<h3 id="8&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6C60;"><a name="8&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6C60;" class="anchor-navigation-ex-anchor" href="#8&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6C60;"><i class="fa fa-link" aria-hidden="true"></i></a>8.&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6C60;</h3>
<pre><code class="lang-java">java.util.concurrent.Executors
</code></pre>
<p>&#x521B;&#x5EFA;&#x4E0D;&#x540C;&#x7684;&#x7EBF;&#x7A0B;&#x6C60;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-comment">// &#x56FA;&#x5B9A;&#x7EBF;&#x7A0B;&#x5927;&#x5C0F;&#x7684;&#x7EBF;&#x7A0B;&#x6C60; corePoolSize = maximumPoolSize = nThreads</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ExecutorService <span class="hljs-title">newFixedThreadPool</span><span class="hljs-params">(<span class="hljs-keyword">int</span> nThreads)</span> </span>;

<span class="hljs-comment">// &#x5355;&#x4E2A;&#x7EBF;&#x7A0B;&#x7684;&#x7EBF;&#x7A0B;&#x6C60; corePoolSize = maximumPoolSize = 1</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ExecutorService <span class="hljs-title">newSingleThreadExecutor</span><span class="hljs-params">()</span>&#xFF1B;

<span class="hljs-comment">// &#x6309;&#x9700;&#x6C42;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6570;&#x91CF;&#x7684;&#x7EBF;&#x7A0B;&#x6C60; corePoolSize = 0  maximumPoolSize = Integer.MAX_VALUE</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ExecutorService <span class="hljs-title">newCachedThreadPool</span><span class="hljs-params">()</span>&#xFF1B;


<span class="hljs-comment">// &#x5355;&#x7EBF;&#x7A0B; &#x4EFB;&#x52A1;&#x8C03;&#x5EA6; &#x7684; &#x7EBF;&#x7A0B;&#x6C60;</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ScheduledExecutorService <span class="hljs-title">newSingleThreadScheduledExecutor</span><span class="hljs-params">()</span> &#xFF1B;

<span class="hljs-comment">// &#x591A;&#x7EBF;&#x7A0B; &#x4EFB;&#x52A1;&#x8C03;&#x5EA6; &#x7684; &#x7EBF;&#x7A0B;&#x6C60;</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ScheduledExecutorService <span class="hljs-title">newScheduledThreadPool</span><span class="hljs-params">(<span class="hljs-keyword">int</span> corePoolSize)</span> &#xFF1B;
</span></code></pre>
<footer class="page-footer"><span class="copyright">Copyright @copy tianwyam 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-05-13 19:28:31
</span></footer>
                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="java.html" class="navigation navigation-prev " aria-label="Previous page: 计算机基础-操作系统-进程-计算机网络">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="java_ftp.html" class="navigation navigation-next " aria-label="Next page: FTP文件服务器上传下载">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"线程池的工作原理","level":"2.2","depth":1,"next":{"title":"FTP文件服务器上传下载","level":"2.3","depth":1,"path":"java/java_ftp.md","ref":"java/java_ftp.md","articles":[]},"previous":{"title":"计算机基础-操作系统-进程-计算机网络","level":"2.1","depth":1,"path":"java/java.md","ref":"java/java.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","github","tbfed-pagefooter","splitter","pageview-count","anchor-navigation-ex","chapter-fold","expandable-chapters-small","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright @copy tianwyam 2021","modify_label":"最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"github":{"url":"https://github.com/tianwyam"},"livereload":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"pageview-count":{},"expandable-chapters-small":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tianwyam","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"JAVA学习积累","links":{"sidebar":{"博客Blog":"https://blog.csdn.net/mybook201314"}},"gitbook":"*","description":"积累Java学习过程中的知识点，俗话说：好记性不如烂笔头"},"file":{"path":"java/java_thread_pool.md","mtime":"2021-05-13T11:28:31.038Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-03T12:24:01.188Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

